<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>13.form-serialize插件使用</title>
</head>

<body>
  <form action="javascript:;" class="example-form">
    <input type="text" name="uname">
    <br>
    <input type="text" name="pwd">
    <br>
    <input type="button" class="btn" value="提交">
  </form>
  <!-- 
    目标：在点击提交时，使用form-serialize插件，快速收集表单元素值
  -->
    <!-- 1。把插件引入到自己的网页中 -->
  <script src="../代码和笔记/Day01_AJAX入门/03-code/lib/form-serialize.js"></script>
  <script>
    document.querySelector('.btn').addEventListener('click', () => {
      //  2.使用serialize函数，快速收集表单元素的值
      const form = document.querySelector('.example-form')
      // const data = serialize(form, {hash: true, empty: true})
      // const data = serialize(form, {hash: false, empty: true})
      const data = serialize(form, {hash: true, empty: true})

      console.log(data)
      
    })
  </script>
</body>

</html>